﻿/*
 *	Copyright (c) 2009 Queensland University of Technology. All rights reserved.
 *	The QUT Bioinformatics Collection is open source software released under the 
 *	Microsoft Public License (Ms-PL): http://www.microsoft.com/opensource/licenses.mspx.
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using QUT.Bio.SilverMap.ObjectModel;

namespace QUT.Bio.SilverMap {
	/// <summary>
	/// HistoryItem is intended to support chronological recording of the reference sequence.
	/// <para>The functionality has been removed, but it may reappear.</para>
	/// </summary>

	public class HistoryItem : IComparable<HistoryItem>, INotifyPropertyChanged {
		private readonly ILinearDomain sequence;
		private DateTime time;

		public event PropertyChangedEventHandler  PropertyChanged;

		public HistoryItem ( ILinearDomain sequence ) {
			this.sequence = sequence;
			this.time = DateTime.Now;
		}

		public ILinearDomain Sequence {
			get {
				return sequence;
			}
		}

		public DateTime Time {
			get {
				return time;
			}
			set {
				if ( ! time.Equals( value ) ) {
					time = value;
					
					if ( PropertyChanged != null ) {
						PropertyChanged( this, new PropertyChangedEventArgs( "Time" ) );
						PropertyChanged( this, new PropertyChangedEventArgs( "TimeLiteral" ) );
					}
				}
			}
		}
		
		public string TimeLiteral {
			get {
				return time.TimeOfDay.ToString();
			}
		}

		public int CompareTo ( HistoryItem other ) {
			return sequence.CompareTo( other.Sequence );
		}

		public override bool Equals ( object obj ) {
			return CompareTo( ( (HistoryItem) obj ) ) == 0;
		}

		public override int GetHashCode () {
			return sequence.GetHashCode();
		}

		public override string ToString () {
			return sequence.Name;
		}
	}
}
